/***************************************
 * 存储 相关
 ***************************************/
$.extend($app, {
	
	/**
	 * sessionStorage 存
	 **/
	setSession: function(settings, name) {
		var settingA = settings || {};
		sessionStorage.setItem(name, JSON.stringify(settingA));
	},

	/**
	 * sessionStorage 读
	 **/
	getSession: function(name) {
		var settingsText = sessionStorage.getItem(name);
		return JSON.parse(settingsText);
	},
	/**
	 * sessionStorage 删
	 **/
	removeSession: function(name) {
		sessionStorage.removeItem(name);
	},
	/**
	 * HTML5本地存储 设置应用本地配置
	 * settings:保存数据
	 * name:保存数据名
	 **/
	setSettings: function(settings, name) {
		var settingA = settings || {};
		localStorage.setItem(name, JSON.stringify(settingA));
	},
	/**
	 * 获取HTML5本地存储的数据
	 * 获取数据：localStorage.getItem(key)
	 * 获取全部数据：localStorage.valueOf()
	 * 删除数据：localStorage.removeItem(key) 
	 * 清空全部数据：localStorage.clear();
	 * 获取本地存储数据数量：localStorage.length
	 * 获取第 N 个数据的 key 键值：localStorage.key(N)
	 **/
	getSettings: function(name) {
		var settingsText = localStorage.getItem(name);
		return JSON.parse(settingsText);
	},
	/**
	 * 删除应用本地配置
	 **/
	removeSettings: function(name) {
		localStorage.removeItem(name);
	},
	/**
	 * 获取cookie
	 **/
	getCookie: function(name) {
		var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
		if (arr = document.cookie.match(reg)) {
			return unescape(arr[2]);
		} else {
			return null;
		}
	}
});
